/*
 * ExchangeAndRefundListItem.java
 * business
 *
 * Created by ChenTao on 2017/2/28.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.displaylistitem;

import android.app.Activity;
import android.content.Context;
import android.view.View;

import com.yidiandao.business.data.bean.Goods;
import com.yidiandao.business.data.bean.Order;
import com.yidiandao.business.ui.goodsdetail.GoodsDetailActivity;
import com.yidiandao.business.ui.orderabout.orderdetail.OrderDetailActivity;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.listview.viewholder.ExchangeHolder;
import com.yidiandao.business.ui.widget.view.OrderGoodsInfoLayout;

import java.util.List;

/** 退换货 */
public class ExchangeListItem extends DisplayListItem<ExchangeHolder, Order> {

    public ExchangeListItem(Order s) {
        super(s);
    }

    @Override
    public void onShow(final Context context, ExchangeHolder holder) {
        //订单id
        final String orderId = data.getOrderId();
        //订单编号
        holder.mTvOrderNum.setText(data.getOrderSn());
        final List<Goods> goodsList = data.getGoodsList();
        //商品信息
        holder.mInfoLayout.setData(goodsList);
        //订单状态
        holder.mTvState.setText(data.getOrderStatus());
        List<String> buttons = data.getButtons();
        if (buttons != null && buttons.size() > 0) {
            holder.mOrderStatusView.setVisibility(View.VISIBLE);
            holder.mOrderStatusView.setData((Activity) context, orderId, buttons, goodsList);
        } else {
            holder.mOrderStatusView.setVisibility(View.GONE);
        }

        //查看订单信息
        holder.mInfoLayout.setOnItemClickListener(
                new OrderGoodsInfoLayout.OnItemClickListener() {
                    @Override
                    public void onItemClick(int position, String goodsId) {
                        OrderDetailActivity.actionStart((Activity) context, data.getOrderId());
                    }
                });

        holder.mInfoLayout.setOnItemClickListener(
                new OrderGoodsInfoLayout.OnItemClickListener() {
                    @Override
                    public void onItemClick(int position, String goodsId) {
                        GoodsDetailActivity.actionStart((Activity) context, goodsId);
                    }
                });
    }

    @Override
    public String getDisplayItemTag() {
        return ExchangeListItem.class.getSimpleName();
    }

    @Override
    public Class<ExchangeHolder> getViewHolderClazz() {
        return ExchangeHolder.class;
    }
}
